<template>
  <van-collapse v-model="activeName" accordion class="panel-apply-filter">
    <van-collapse-item title="高级查询" name="1" icon="filter-o">
      <van-cell>
        <van-dropdown-menu>
          <van-dropdown-item v-model="carrier" :options="carrierOption" />
          <van-dropdown-item v-model="status" :options="statusOption" />
        </van-dropdown-menu>
      </van-cell>
      <van-cell style="text-align: center">
        <van-button size="small" block type="primary" @click="doClick">查询</van-button>
      </van-cell>
    </van-collapse-item>
  </van-collapse>
</template>

<script>
import { getCarrierList } from '@/api/assess'
export default {
  name: 'PanelRaiseFilter',
  props: ['assessType'],
  data () {
    return {
      activeName: '',
      carrier: '',
      status: '',
      carrierOption: [
        { text: '全部载体', value: '' }
      ],
      statusOption: [
        { text: '全部申请', value: '' },
        { text: '待审核', value: this.$vo.ApplyStatus.CREATE + '' },
        { text: '已审核', value: this.$vo.ApplyStatus.CHECK + '' },
        { text: '已复核', value: this.$vo.ApplyStatus.RECHECK + '' },
        { text: '局领导审核', value: this.$vo.ApplyStatus.REVIEW + '' },
        { text: '待修改', value: this.$vo.ApplyStatus.MODIFY + '' },
        { text: '已完成', value: this.$vo.ApplyStatus.FINAL + '' }
      ]
    }
  },
  mounted () {
    getCarrierList(this.$vo.CarrierType.ADD).then(res => {
      let { data } = res
      if (data[this.$response.CODE] === this.$response.SUCCESS) {
        let str = JSON.stringify(data[this.$response.DATA].check_list.sort(this.listSort)).replace(new RegExp('id', 'g'), 'value').replace(new RegExp('item', 'g'), 'text')
        this.carrierOption = this.carrierOption.concat(JSON.parse(str))
      }
    }, errFunc => {
      this.$notify('服务调用失败：' + errFunc.toString())
      console.log(errFunc.toString())
    })
  },
  methods: {
    doClick () {
      let condition = this.$vo.createCondition()
      condition.matters = this.carrier
      condition.apply_status = this.status
      condition.apply_type = this.assessType
      this.$emit('onQuery', condition)
    },
    listSort (obj1, obj2) {
      let val1 = Number(obj1.id)
      let val2 = Number(obj2.id)
      if (val1 < val2) {
        return -1
      } else {
        return 1
      }
    }
  }
}
</script>

<style scoped lang="less">
  .panel-apply-filter{
    .van-collapse-item{
      /deep/ .van-collapse-item__content{
        padding: 0px;
        .van-cell{
          font-size: 12px;
          line-height: 20px;
        }
      }
    }
    /deep/ .van-dropdown-menu__title{
      font-size: 12px;
    }

    /deep/ .van-dropdown-menu__bar {
      height: 40px;
    }
  }
</style>
